package br.uneb.tebd.webservice;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import br.uneb.tebd.R;
import br.uneb.tebd.util.Constants;

public class DeleteByDescriptionWS extends Activity{
	private Button deleteButton;
	private EditText description;
	private EditText text;
	private WebServiceClient client;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.webservice_find);
		
		this.setTitle("Delete Guitar from WebService");
		
		this.client = new WebServiceClient();
		
		this.deleteButton = (Button) findViewById(R.id.searchButtonWeb);
		this.deleteButton.setText("Delete");

		this.text = (EditText) findViewById(R.id.textWeb);
		this.text.setVisibility(View.INVISIBLE);
		
		this.description = (EditText) findViewById(R.id.descriptionSearchWeb);
		
		this.deleteButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				try {
					client.setDescription(description.getText().toString().trim());
					client.setMethod(WebServiceClient.FIND_BY_DESCRIPTION);
					client.Execute();
					if(!client.getResponse().equalsIgnoreCase(Constants.MSG_GUITAR_NOT_FOUND)){
						client.setMethod(WebServiceClient.DELETE_BY_DESCRIPTION);
				    	client.Execute();
						Toast.makeText(DeleteByDescriptionWS.this, client.getResponse(), Toast.LENGTH_SHORT).show();
					} else{
						Toast.makeText(DeleteByDescriptionWS.this, Constants.MSG_GUITAR_NOT_FOUND, Toast.LENGTH_SHORT).show();
					}
				} catch (Exception e) {
				    e.printStackTrace();
				}
			}
		});
	}
}
